<%def name="ws(x=1)">
% for i in range(x):
&nbsp;&nbsp;
% endfor
</%def>

<%inherit file="base.mako" />
<div id='client_data'>
  <h3>Ficha del Cliente</h3>
<table>
${fs.render()}

</table>
Categoria: ${client.category}
% if client.__tablename__ == 'companies':
    % if client.contacts:
    <a href=""><h3>Contactos de la Empresa</h3></a>
    <table border = 1> 
    <tr><td>Nombre</td><td>Email</td><td>Telefono</td><td>Descripccion</td></tr>
        % for contact in client.contacts:
        <tr>
            <td>${contact.name}</td><td>${contact.email}</td><td>${contact.telephone}</td><td>${contact.description}</td>
        </tr>
        % endfor
    </table>
    % endif
% endif

<h3>Historial de Incidencias</h3>
% if incidence_history:
<table>
  <tr>
    <td>Id</td>
    <td>Cola</td>
    <td>Descripcion</td>
    <td>Solucion</td>
    <td>Fecha de Inicio</td>
    <td>Fecha de Fin</td>
    <td>Fecha</td>
  </tr>
% for incidence in incidence_history:
  <tr>
    <td>${incidence.id}</td>
    <td>${incidence.cola}</td>
    <td>${incidence.description}</td>
    <td>${incidence.solution}</td>
    <td>${incidence.start_date}</td>
    <td>${incidence.end_date}</td>
    <td>${incidence.date}</td>
  </tr>
% endfor
</table>
% else:
<h3>No ha tenido ninguna incidencia.</h3>
% endif

</div>
<%
this_url = "/serve_client/main?client_id="+repr(client.id)
%>

<a href = "/tables_admin/new/account?client_id=${client.id}&return_url=${this_url}&readonly=True"><h2>Agregar Cuenta</h2></a>
% if client.accounts:
% for account in client.accounts:
<div id='accountsx'>
  <a href="/tables_admin/new/account_edit?account_id=${account.id}&return_url=${this_url}"><h3>${ws(2)}Cuenta a nombre de ${account.name}</h3></a>
  <table>
  <tr><td>${ws(4)}  NIT:</td><td> ${account.nit}</td></tr>
  <tr><td>${ws(4)}Direccion de Facturacion:  </td><td> ${account.address}</td></tr>
  <tr><td>${ws(4)}Estado: </td><td>  ${account.is_active}</td></tr>
  </table>
  <a href = "/tables_admin/new/contract?account_id=${account.id}"><h2>Crear Contrato</h2></a>
  % if account.contracts:
  % for contract in account.contracts:
  <div id='contract${contract.id}'>
    <a href="/tables_admin/new/contract_edit?contract_id=${contract.id}&return_url=${this_url}"><h3>${ws(4)}Contrato ${contract.id}</h3></a>
	<table>
        <tr><td>${ws(6)}Fecha de inicio: </td><td>  ${contract.start_date}</td></tr>
        <tr><td>${ws(6)}Fecha de finalizacion: </td><td>  ${contract.end_date}</td></tr>
        <tr><td>${ws(6)}Contrato realizado por: </td><td>  ${contract.user}</td></tr>
	</table>

    % if contract.lines:
    % for line_i, line in enumerate(contract.lines):
    <div id='line${line_i}'>
      <a href="/tables_admin/new/edit_line?line_id=${line.id}&return_url=${this_url}"><h3>${ws(6)}Linea ${line_i + 1}</h3></a>
	  <table>
        <tr><td>${ws(8)}Numero Ascociado: </td><td>  ${line.number}</td></tr>
        <tr><td>${ws(8)}Terminal Comprada con el Plan: </td><td> ${repr(products)} ${line.product_name}</td></tr>
	  </table>
        % if line.plans:
        % for plan in line.plans:
        <div id='planx'>
          <a href="/tables_admin/new/change_plan?line_id=${line.id}&return_url=${this_url}"><h3>${ws(10)}Plan ${plan.name}</h3></a>
		  <table>
		  <tr><td>${ws(10)}Descripcion: </td><td>  ${plan.description} </td></tr>
		  </table>
          % if line.services:
          % for service in line.services:
          <div id='servicex'>
            <h3> ${ws(10)}Servicio ${service.name}</h3>
			<table>
			<tr><td>${ws(12)}Descripcion: </td><td> ${service.description}</td></tr>
			</table>
          </div>
          % endfor
          % else:
          <h3>${ws(10)}No tiene servicios.</h3>
          % endif
        </div>
        % endfor
        % else:
        <h3>${ws(8)}No tiene planes asociados.</h3>
        % endif
    </div>
    % endfor
    % else:
    <h3>${ws(6)}no tiene lineas asociadas.</h3>
    % endif
    </div>
  % endfor
  % else:
  <h3>${ws(4)}No tiene contratos asociados.</h3>
  % endif

</div>
% endfor
% else:
${ws(2)}No tiene cuentas asociadas.
% endif
<div id='historial'>

</div>
